package com.aps.common.model;

import com.aps.common.model.genetic.OrderProcess;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 订单数据模型
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "订单数据模型")
public class OrderAbandoned {
    
    @NotBlank(message = "订单ID不能为空")
    @JsonProperty("orderId")
    @Schema(description = "订单ID", example = "ORD001")
    private String orderId;
    
    @NotBlank(message = "客户名称不能为空")
    @JsonProperty("customerName")
    @Schema(description = "客户名称", example = "大众汽车")
    private String customerName;
    
    @NotBlank(message = "客户等级不能为空")
    @JsonProperty("customerLevel")
    @Schema(description = "客户等级", example = "A")
    private String customerLevel;
    
    @NotBlank(message = "产品型号不能为空")
    @JsonProperty("productModel")
    @Schema(description = "产品型号", example = "GEAR-001")
    private String productModel;
    
    @Positive(message = "订单数量必须为正数")
    @JsonProperty("quantity")
    @Schema(description = "订单数量", example = "1000")
    private Integer quantity;
    
    @NotNull(message = "交期不能为空")
    @JsonProperty("deliveryDate")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(description = "交期", example = "2024-06-30")
    private LocalDateTime deliveryDate;
    
    @NotBlank(message = "优先级不能为空")
    @JsonProperty("priority")
    @Schema(description = "优先级", example = "高")
    private String priority;
    
    @Positive(message = "订单金额必须为正数")
    @JsonProperty("orderAmount")
    @Schema(description = "订单金额", example = "50000.00")
    private BigDecimal orderAmount;

    @JsonProperty("operations")
    @Schema(description = "订单包含的所有工序")
    /** 该订单包含的所有工序列表（按工序顺序排列） */
    private List<OrderProcess> orderProcesses;

    @JsonProperty("orderPlanStartTime")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(description = "订单计划开始日期")
    private LocalDateTime orderPlanStartTime;

    /**
     * 构造函数
     *
     * @param id 订单ID
     * @param quantity 订单数量
     * @param startDate 开始时间
     * @param dueDate 交付日期
     */
    public OrderAbandoned(String id, int quantity, LocalDateTime startDate, LocalDateTime dueDate) {
        if (quantity <= 0) {
            throw new IllegalArgumentException("订单数量必须大于0");
        }
        if (startDate.isAfter(dueDate)) {
            throw new IllegalArgumentException("开始时间不能晚于交付时间");
        }

        this.orderId = id;
        this.quantity = quantity;
        this.orderPlanStartTime = startDate;
        this.deliveryDate = dueDate;
        this.orderProcesses = new ArrayList<>();
    }
    
    /**
     * 订单优先级枚举
     */
    @Schema(description = "订单优先级枚举")
    public enum Priority {
        HIGH("高"),
        MEDIUM("中"),
        LOW("低");
        
        private final String description;
        
        Priority(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
    
    /**
     * 客户等级枚举
     */
    @Schema(description = "客户等级枚举")
    public enum CustomerLevel {
        A("A级客户"),
        B("B级客户"),
        C("C级客户");
        
        private final String description;
        
        CustomerLevel(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
} 